-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.c
35 lines (31 loc) · 842 Bytes
/
Solution.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>
#include <stdlib.h>
int maxRectangleArea(int heights[], int n) {
int maxArea = 0;
for (int i = 0; i < n; i++) {
int minHeight = heights[i];
for (int j = i; j < n; j++) {
if (heights[j] < minHeight) {
minHeight = heights[j];
}
int area = minHeight * (j - i + 1);
if (area > maxArea) {
maxArea = area;
}
}
}
return maxArea;
}
int main() {
int n;
printf("Enter the number of bars in the histogram: ");
scanf("%d", &n);
int heights[n];
printf("Enter the heights of the bars: ");
for (int i = 0; i < n; i++) {
scanf("%d", &heights[i]);
}
int result = maxRectangleArea(heights, n);
printf("Maximum area of rectangle: %d\n", result);
return 0;
}